#include "entity.h"

#include <QUuid>

namespace Opl { namespace Core {

class EntityPrivate{
    public:
    EntityPrivate():
    unique(qHash(QUuid::createUuid()))
    ,stamp(QDateTime::currentDateTime())
    ,tag(QVariant(0))
    {}
        ~EntityPrivate() {}
        Entity::EntityId unique;
        QDateTime stamp;
        QVariant tag;
};

Entity::Entity() :
    O_PRIVATE_CREATE(Entity)
{
    O_D(Entity);
}

Entity::~Entity()
{
    O_PRIVATE_DELETE;
}

const Entity::EntityId& Entity::unique()const
{
    O_D(const Entity);
    return d->unique;
}

const QDateTime& Entity::stamp()const
{
    O_D(const Entity);
    return d->stamp;
}

const QVariant& Entity::tag()const
{
    O_D(const Entity);
    return d->tag;
}

void Entity::setTag(const QVariant& data)
{
    O_D(Entity);
    d->tag = data;
}

QString Entity::toString()
{
    O_D(Entity);
    return QString("[Entity(id:%2 stamp:%3 tag:%4)]").arg(unique()).arg(d->stamp.toMSecsSinceEpoch()).arg(d->tag.typeName());
}

}}
